package models

import (
	"time"

	"gorm.io/gorm"
)

// Transaction 交易记录表
type Transaction struct {
	gorm.Model
	TransactionID   string    `gorm:"type:varchar(50);uniqueIndex;not null" json:"transaction_id"`
	CardID          string    `gorm:"type:varchar(50);index;not null" json:"card_id"`
	TransactionType string    `gorm:"type:varchar(50);not null" json:"transaction_type"`
	Amount          float64   `gorm:"type:decimal(20,2);not null" json:"amount"`
	Currency        string    `gorm:"type:varchar(10);not null" json:"currency"`
	Status          string    `gorm:"type:varchar(20);not null" json:"status"`
	MatrixAccount   string    `gorm:"type:varchar(50);index;not null" json:"matrix_account"`
	Platform        string    `gorm:"type:varchar(20);not null" json:"platform"`
	RawData         JSONMap   `gorm:"type:json" json:"raw_data"`
	ProcessedAt     time.Time `json:"processed_at"`
	UserCard        UserCard  `gorm:"foreignKey:CardID;references:CardID" json:"user_card"`
}

// Settlement 结算记录表
type Settlement struct {
	gorm.Model
	TransactionID  string    `gorm:"type:varchar(50);uniqueIndex;not null" json:"transaction_id"`
	CardID         string    `gorm:"type:varchar(50);index;not null" json:"card_id"`
	SettlementType string    `gorm:"type:varchar(50);not null" json:"settlement_type"`
	Amount         float64   `gorm:"type:decimal(20,2);not null" json:"amount"`
	Currency       string    `gorm:"type:varchar(10);not null" json:"currency"`
	Status         string    `gorm:"type:varchar(20);not null" json:"status"`
	MatrixAccount  string    `gorm:"type:varchar(50);index;not null" json:"matrix_account"`
	Platform       string    `gorm:"type:varchar(20);not null" json:"platform"`
	RawData        JSONMap   `gorm:"type:json" json:"raw_data"`
	SettledAt      time.Time `json:"settled_at"`
	UserCard       UserCard  `gorm:"foreignKey:CardID;references:CardID" json:"user_card"`
}
